<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>Title</title>
    <link rel="stylesheet" type="text/css" href="http://101.227.72.204/css/easyui.css">
    <link rel="stylesheet" type="text/css" href="http://101.227.72.204/css/icon.css">
    <script src="http://101.227.72.204/js/jquery.min.js"></script>
    <script src="http://101.227.72.204/js/jquery.easyui.min.js"></script>
    <style type="text/css">
        #projects {
            float: left;
        }

        #project_introduce {
            float: left;
        }

        #agreement {
            float: left;
        }

        #project_introduce {
            margin-top: 13px;
            margin-left: 50px;
        }

        #agreement {
            margin-left: 50px;
            margin-right: 50px;
        }
    </style>
</head>
<body>
<div id="projects">
    <form id="fm_projects" name="fm_projects" method="post" enctype="multipart/form-data">
        <table class="detail">
            <tr style="height: 50px;width: 100px;">
                <td height="20px">项目标题</td>
                <td><input class="easyui-textbox easyui-validatebox" required="true" type="text" name="title"
                           id="title_project"
                           style="height: 20px"/></td>
            </tr>

            <tr style="height: 50px;">
                <td height="20px">优势</td>
                <td><input class="easyui-textbox easyui-validatebox" required="true" type="text" id="advantage_project"
                           name="advantage" style="height: 20px"/></td>
            </tr>

            <tr style="height: 50px;">
                <td height="20px">项目名称</td>
                <td><input class="easyui-textbox easyui-validatebox" required="true" type="text" id="name_project"
                           name="name" style="height: 20px"/></td>
            </tr>

            <tr style="height: 50px;">
                <td height="20px">总融资金额</td>
                <td><input class="easyui-numberbox easyui-validatebox" required="true" type="text"
                           id="financing_project"
                           name="financing" style="height: 20px"/></td>
            </tr>

            <tr style="height: 50px;">
                <td height="20px">预计发货时间</td>
                <td><input class="easyui-textbox easyui-validatebox" required="true" type="text"
                           id="dispatchTime_project"
                           name="dispatchTime" style="height: 20px"/></td>
            </tr>

            <tr>
                <td height="20px">产品所属活动</td>
                <td>
                    <select class="easyui-combobox" name="modelId" id="modelId_project" style="width: 100px;">
                        <option value=19023>0元认购</option>
                        <option value=19024>热门推荐</option>
                    </select>
                </td>
            </tr>

            <tr>
                <td height="20px">是否可超募</td>
                <td>
                    <select class="easyui-combobox" name="overflow" id="overflow_project" style="width: 100px;">
                        <option value=0>否</option>
                        <option value=10>是</option>
                    </select>
                </td>
            </tr>

            <tr style="height: 50px;">
                <td height="20px">发布时间</td>
                <td><input class="easyui-textbox" required="true" type="text" name="publish_time"
                           id="publish_time_project"
                           style="height: 20px"/>例如 2019-02-11
                </td>
            </tr>

            <tr style="height: 50px;">
                <td height="20px">结束时间</td>
                <td><input class="easyui-textbox" required="true" type="text" name="endData" id="endDate_project"
                           style="height: 20px"/>例如 2019-02-11 大于当前时间
                </td>
            </tr>

            <tr>
                <td height="20px">状态</td>
                <td>
                    <select class="easyui-combobox" name="statusCode" id="statusCode_project" style="width: 100px;">
                        <option value=0>预热</option>
                        <option value=10>众筹</option>
                        <option value=20>已完成</option>
                    </select>
                </td>
            </tr>

            <tr style="height: 50px;">
                <td height="20px">产品小类型</td>
                <td><select class="easyui-combobox" name="tags" id="tags_project" style="width: 100px;">
                    <option value=0>科技</option>
                    <option value=10>农业</option>
                    <option value=20>娱乐</option>
                    <option value=30>公益</option>
                    <option value=40>艺术</option>
                    <option value=50>其他</option>
                </select></td>
            </tr>

            <tr style="height: 50px;">
                <td height="20px">省</td>
                <td><input class="easyui-textbox" required="true" type="text" name="province" id="province_project"
                           style="height: 20px"/></td>
            </tr>

            <tr style="height: 50px;">
                <td height="20px">市</td>
                <td><input class="easyui-textbox" required="true" type="text" id="city_project"
                           name="city" style="height: 20px"/></td>
            </tr>

            <tr style="height: 50px;">
                <td height="20px">城市中详细地址</td>
                <td><input class="easyui-textbox" required="true" type="text" id="area_project"
                           name="area" style="height: 20px"/></td>
            </tr>
        </table>
    </form>
    <a href="#" class="easyui-linkbutton submitProject">提交project</a>
    <br/><br/>
    <form id="fm_projects_cover" name="fm_projects_cover" method="post" enctype="multipart/form-data">
        <tr style="height: 50px;">
            <td height="20px">产品封面</td>
            <td style="margin-left: 20px;">
                <input type="file" id="cover" name="cover" style="margin-left: 20px;"/>
            </td>
        </tr>
    </form>
    <a href="#" class="easyui-linkbutton submitProjectCover">提交产品封面</a>
</div>
<div id="project_introduce">
    <form id="fm_project_introduce" name="fm_project_introduce" method="post" enctype="multipart/form-data">
        <table class="detail">
            <tr>
                <td height="20px">类型</td>
                <td>
                    <select class="easyui-combobox" name="type" id="type_project_introduce" style="width: 100px;">
                        <option value=10>产品介绍</option>
                        <option value=40>团队介绍</option>
                        <option value=50>项目进展</option>
                    </select>
                </td>
            </tr>

            <tr style="height: 50px;">
                <td height="20px">内容</td>
                <td><input class="easyui-textbox easyui-validatebox" required="true" type="text"
                           id="content_project_introduce"
                           name="content" style="height: 20px"/></td>
            </tr>

            <tr>
                <td height="20px">内容类型</td>
                <td>
                    <select class="easyui-combobox c_type_project_introduce" name="c_type" style="width: 100px;"
                            id="c_type_project_introduce">
                        <option value=10>文本</option>
                        <option value=20>图片</option>
                        <option value=30>视频</option>
                        <option value=40>音频</option>
                    </select>
                </td>
            </tr>

            <tr>
                <td height="20px">项目优先级</td>
                <td>
                    <select class="easyui-combobox c_type_project_introduce" name="tum" style="width: 100px;"
                            id="tum_agreement">
                        <option value=1>1</option>
                        <option value=2>2</option>
                        <option value=3>3</option>
                        <option value=4>4</option>
                        <option value=5>5</option>
                    </select>
                </td>
            </tr>

            <tr style="height: 50px;">
                <td height="20px">标志图</td>
                <td>
                    <input type="file" id="project_introduce_cover" name="introduce_cover"/>
                    当你内容类型选择为图片时候，再选择标志图
                </td>
            </tr>
        </table>
    </form>
    <a href="#" class="easyui-linkbutton submitProjectIntroduce">提交项目描述</a>
</div>

<%--<div id="agreement">
    <form id="fm_agreement" name="fm_agreement" method="post" enctype="multipart/form-data">
        <table class="detail">
            <tr style="height: 50px;width: 100px;">
                <td height="20px">开始时间</td>
                <td><input class="easyui-textbox easyui-validatebox" required="true" type="text" name="startTime" id="startTime_agreement"
                           style="height: 20px"/></td>
            </tr>
            <tr style="height: 50px;width: 100px;">
                <td height="20px">结束时间</td>
                <td><input class="easyui-textbox easyui-validatebox" required="true" type="text" name="endTime" id="endTime_agreement"
                           style="height: 20px"/></td>
            </tr>
            <tr style="height: 50px;width: 100px;">
                <td height="20px">成本</td>
                <td><input class="easyui-numberbox easyui-validatebox" precision="5" required="true" type="text" name="costing" id="costing_agreement"
                           style="height: 20px"/></td>
            </tr>
            <tr style="height: 50px;width: 100px;">
                <td height="20px">协议价</td>
                <td><input class="easyui-numberbox easyui-validatebox" precision="5" required="true" type="text" name="settlement" id="settlement_agreement"
                           style="height: 20px"/></td>
            </tr>
            <tr style="height: 50px;width: 100px;">
                <td height="20px">售价</td>
                <td><input class="easyui-numberbox easyui-validatebox" precision="5" required="true" type="text" name="sale" id="sale_agreement"
                           style="height: 20px"/></td>
            </tr>
            <tr style="height: 50px;width: 100px;">
                <td height="20px">服务百分比</td>
                <td><input class="easyui-numberbox easyui-validatebox" precision="5" required="true" type="text" name="service" id="service_agreement"
                           style="height: 20px"/></td>
            </tr>
            <tr style="height: 50px;width: 100px;">
                <td height="20px">bouns</td>
                <td><input class="easyui-numberbox easyui-validatebox" required="true" precision="5" type="text" name="bonus" id="bonus_agreement"
                           style="height: 20px"/></td>
            </tr>
        </table>
        <a href="#" class="easyui-linkbutton submitAgreement">提交project参数</a>
    </form>
</div>--%>

<div id="skus">
    <form id="fm_skus" name="fm_skus" method="post" enctype="multipart/form-data">
        <table class="detail">
            <tr style="height: 50px;width: 100px;">
                <td height="20px">名字</td>
                <td><input class="easyui-textbox easyui-validatebox" required="true" type="text" name="name"
                           id="name_skus"
                           style="height: 20px"/></td>
            </tr>

            <tr style="height: 50px;width: 100px;">
                <td height="20px">单价</td>
                <td><input class="easyui-numberbox easyui-validatebox" precision="5" required="true" type="text"
                           name="unitPrice" id="unitPrice_skus"
                           style="height: 20px"/></td>
            </tr>

            <tr style="height: 50px;width: 100px;">
                <td height="20px">派送费用</td>
                <td><input class="easyui-numberbox easyui-validatebox" precision="3" required="true" type="text"
                           name="dispatchPrice" id="dispatch_price_skus"
                           style="height: 20px"/></td>
            </tr>

            <tr style="height: 50px;width: 100px;">
                <td height="20px">最大人数</td>
                <td><input class="easyui-numberbox easyui-validatebox" required="true" type="text"
                           name="maxPeople" id="max_people_skus"
                           style="height: 20px"/></td>
            </tr>

            <tr style="height: 50px;width: 100px;">
                <td height="20px">得到的产品</td>
                <td><input class="easyui-textbox easyui-validatebox" required="true" type="text" name="earnings"
                           id="earnings_skus"
                           style="height: 20px"/></td>
            </tr>

            <tr style="height: 50px;">
                <td height="20px">sku标志图</td>
                <td style="margin-left: 20px;">
                    <input type="file" id="cover_skus" name="cover_skus" style="margin-left: 20px;"/>
                </td>
            </tr>
        </table>
    </form>
    <a href="#" class="easyui-linkbutton submitSkus">提交skus</a>
</div>
<input type="hidden" id="projectId" name="projectId"/>
<script type="text/javascript">

    function slide(data) {
        $.messager.show({
            title: '错误提示',
            msg: data,
            width: 250,
            height: 200,
            timeout: 3000,
            showType: 'slide'
        });
    }

    function setMessage(msg) {
        var returnMsg = '';
        for (var key in msg) {
            if(key == "status" && msg[key] == "ok"){
                returnMsg = "操作成功";
            }
            if (key == 'ERROR') {
                var childObj = msg[key];
                for (var v in childObj) {
                    returnMsg = childObj[v] + ';';
                }
            }
        }
        return returnMsg;
    }

    function loadSuccess(msg) {
        var errorInfo = setMessage(msg);
        if (errorInfo != '') {
            //有错误信息弹出提示
            slide(errorInfo);
        }
    }

    $(document).ready(function () {
        $('.submitProjectIntroduce').click(function () {
            $('#fm_project_introduce').form('submit', {
                url: '/single/admin/project/createProjectIntroduce/' + $('#projectId').val(),
                onSubmit: function () {
                },
                success: function (data) {
                    loadSuccess(data);
                },
                error: function(obj){
                    slide(obj.getAllResponseHeaders());
                }
            });
        });

        $('.submitProjectCover').click(function () {
            $('#fm_projects_cover').form('submit', {
                url: '/single/admin/project/createCover/' + $('#projectId').val(),
                onSubmit: function () {
                },
                success: function (data) {
                    loadSuccess(data);
                },
                error: function(obj){
                    slide(obj.getAllResponseHeaders());
                }
            });
        });

        $('.submitSkus').click(function () {
            if($('#projectId').val()==null || $('#projectId').val() ==''){
                slide("请先提交产品");
                return;
            }
            $('#fm_skus').form('submit', {
                url: '/single/admin/skus/create/' + $('#projectId').val(),
                onSubmit: function () {
                },
                success: function (data) {
                    loadSuccess(data);
                },
                error: function(obj){
                    slide(obj.getAllResponseHeaders());
                }
            });
        });

        $('.submitAgreement').click(function () {
            $.ajax({
                url: '/single/project/agreement/add',
                type: "POST",
                contentType: "application/json; charset=utf-8",
                dataType: "json",
                data: JSON.stringify({
                    "projectId": $('#projectId').val(),
                    "startTime": $('#startTime_agreement').val(),
                    "endTime": $('#endTime_agreement').val(),
                    "costing": $('#costing_agreement').val(),
                    "settlement": $('#settlement_agreement').val(),
                    "sale": $('#sale_agreement').val(),
                    "service": $('#service_agreement').val(),
                    "bonus": $('#bonus_agreement').val(),
                }),
                success: function (obj) {
                    loadSuccess(data);
                },
                error: function(obj){
                    slide(obj.getAllResponseHeaders());
                }
            });

        });

        $('.submitProject').click(function () {
            $.ajax({
                url: '/single/project/create',
                type: "POST",
                contentType: "application/json; charset=utf-8",
                dataType: "json",
                data: JSON.stringify({
                    "title": $('#title_project').val(),
                    "advantage": $('#advantage_project').val(),
                    "name": $('#name_project').val(),
                    "financing": $('#financing_project').val(),
                    "overflow": $('#overflow_project').combobox('getValue'),
                    "endData": $('#endDate_project').val(),
                    "publishTime": $('#publish_time_project').val(),
                    "statusCode": $('#statusCode_project').val(),
                    "tags": $('#tags_project').combobox('getValue'),
                    "province": $('#province_project').val(),
                    "city": $('#city_project').val(),
                    "area": $('#area_project').val(),
                    "dispatchTime": $('#dispatchTime_project').val(),
                    "modelId": $('#modelId_project').combobox('getValue'),
                }),
                success: function (obj) {
                    for (var key in obj) {
                        if (key == 'data') {
                            var childObj = obj[key];
                            for (var v in childObj) {
                                if (v == "projectId") {
                                    $('#projectId').val(childObj[v])
                                }
                            }
                        }
                    }

                    loadSuccess(obj);
                },
                error: function (obj) {
                    slide(obj.getAllResponseHeaders());
                }
            });
        });
    });
</script>
</body>
</html>
